package com.me.hippy.sdk.demo.chat

import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import com.blankj.utilcode.util.ConvertUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.me.hippy.sdk.R
import kotlinx.android.synthetic.main.activity_newchat_new.*

class AiliaoChatActivity : FragmentActivity(), KeyboardChangeListener.C1117a {
    private lateinit var listAdapter: ListAdapter
    private val dataList = mutableListOf<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

//        val systemStatusManager = SystemStatusManager(this)
//        systemStatusManager.mo57451a(true)
//        systemStatusManager.mo57450a(0xff000000.toInt())
//        setInitStatusBar()
        setContentView(R.layout.activity_newchat_new)
//        initTestDatas()
        val keyboardChangeListener = KeyboardChangeListener(this)
        keyboardChangeListener.mo14613a(this)
        window.setSoftInputMode(19)
//        rootView.fitsSystemWindows = true
//        list.layoutManager = LinearLayoutManager(this)
//
//        listAdapter = ListAdapter(dataList)
//        list.adapter = listAdapter

//        btn_send.setOnClickListener {
//            sendMessage(et_input.text.toString())
//            et_input.text.clear()
//
//            val att = window.attributes
//            val softInputMode = att.softInputMode
//            Log.e("===========", "softInputMode:$softInputMode")
//        }
//        btn_add.setOnClickListener {
//            fl_keyboard.visibility = View.VISIBLE
//        }
//        et_input.addTextChangedListener {
//            if (TextUtils.isEmpty(it.toString())) {
//                btn_add.visibility = View.VISIBLE
//                btn_send.visibility = View.GONE
//            } else {
//                btn_add.visibility = View.GONE
//                btn_send.visibility = View.VISIBLE
//            }
//        }
    }

    private fun sendMessage(msg: String) {
        listAdapter.addData(msg)
    }

    private fun initTestDatas() {
        for (i in 1..20) {
            dataList.add("初始数据>>$i")
        }
    }

    class ListAdapter : BaseQuickAdapter<String, ListAdapter.MyViewHolder> {
        constructor(data: MutableList<String>?) : super(0, data)

        override fun convert(holder: MyViewHolder, item: String) {
            holder.titleTv?.text = item
        }

        override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
            val titleTv = TextView(parent.context)
            titleTv.setPadding(
                ConvertUtils.dp2px(10f),
                ConvertUtils.dp2px(10f),
                ConvertUtils.dp2px(10f),
                ConvertUtils.dp2px(10f)
            )
            titleTv.setTextColor(0xff000000.toInt())
            val viewHolder = MyViewHolder(titleTv)
            viewHolder.titleTv = titleTv
            return viewHolder
        }

        class MyViewHolder : BaseViewHolder {
            var titleTv: TextView? = null

            constructor(view: View) : super(view)
        }
    }

    private fun setInitStatusBar() {
        if (Build.VERSION.SDK_INT >= 21) {
            window.addFlags(Int.MIN_VALUE)
            window.clearFlags(67108864)
            window.statusBarColor = 0xffffffff.toInt()
        }
        val i = Build.VERSION.SDK_INT
        if (i >= 23) {
            window.decorView.systemUiVisibility = View.VISIBLE
        } else if (i >= 21) {
            window.statusBarColor = 0xff000000.toInt()
        }
    }

    override fun mo14615a(z: Boolean, i: Int) {
        Log.e("=======", "z:$z , i=$i")
        if(z){
            val layoutParams = toolPanel.layoutParams
            layoutParams.height = i
            toolPanel.layoutParams = layoutParams
        }else{
            val layoutParams = toolPanel.layoutParams
            layoutParams.height = 0
            toolPanel.layoutParams = layoutParams
        }
    }
}